//
//  VisitorTableViewController.swift
//  XinLangWeiBo
//
//  Created by mac on 15/11/3.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    ///用户登录标记
    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon
    //访客视图
    var visitorView: VisitorView?
    
    
    
    override func loadView() {
        
        userLogon ? super.loadView() :setupVisitorView()
        
    }
    
    func setupVisitorView() {
        
        visitorView = VisitorView()
        view = visitorView
        //添加监听方法
      visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
       // view.backgroundColor = UIColor .whiteColor()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style:  UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style:  UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidLogin")
    }
    
    
    
}


// MARK: - 访客视图监听方法
extension VisitorTableViewController {
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        print("登录")
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}

